<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="common/taglibs.jsp" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	     <title>员工信息</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/layout.css" />
	</head>
	<body>
<div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="common/head.jsp"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：基本资料管理 &gt; 员工信息管理</div>
	<div id="REC_content">
	    <fieldset id="BasicInfo" class="mainField">
		    <legend><span class="title">员工信息管理</span></legend>
			<div class="innerCon">
			    <div class="mainSearchBox">
			    
			       <table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
					<tr height="35">
					    <form:form action="staff.do" method="post" enctype="multipart/form-data" modelAttribute="staff">
						<td width="80" class="title">员工姓名</td>
						<td align="left"><form:input path="staffName" id="staffName"/></td>
						<td width="80" class="title">入厂日期</td>
						<td align="left"><form:input path="enterTime" id="enterTime"/>&nbsp;例:格式为1900-01-01</td>
						<td width="190" align="left">
						  <input type="button" name="searchButton" class="newSearchButton" value="新增" onclick="create()"/> 
						  <input type="submit" name="searchButton" class="newSearchButton" value="查询" /> 
						</td>
						</form:form>
					</tr>
					<tr id="moresearchCon">
						<td class="title" height="30">文件导入</td>
						<td colspan="4">
						  <form action="importStaff.do" method="post" enctype="multipart/form-data">
						  <input type="file" name="excelFile" id="file1" /><img id="loading" src="img/loading.gif" style="display:none" />
				          <input type="submit" class="newSearchButton" value="导入" />
				          <a href="<%=basePath%>OrderExcel/staff.xls">模板下载</a>
				          </form>
						</td>
					</tr>
				</table>
				
			    
			    </div>
			    <!-- begin tab -->
			    <div class="topControl clearfix">
				    <div id="JobsMgrTabCon" class="itemTabCon">
					    <ul id="JobsMgrTabs" class="itemTabs">
							<li id="dueTab" class="focus"><a href="<%=basePath%>staff.do" onfocus="this.blur()">员工信息管理</a></li>
							<li id="dueTab" class="blur"><a href="<%=basePath%>ws.do">工序信息管理</a></li>
							<li id="dueTab" class="blur"><a href="<%=basePath%>route.do">路由设置管理</a></li>
					    </ul>
				    </div>
			    </div>
			    
			    
			    <!-- end tab -->
				<div id="mainListCon">
				    <div class="infoCon">
							<div class="info"></div>
					</div>
				    <div id="mLC">
						    <div class="tableCon">
							    <table width="100%" cellpadding="0" id="tableData"  class="listTab" cellspacing="1" >
								    <tr class="tabHead">
								        <td width="10%"  class="blankTd">编号</td>
									    <td width="30%">姓名</td>
										<td width="25%">入厂日期</td>
										<td width="5%">拼音索引</td>
										<td width="30%"></td>
									</tr>
									
									<c:forEach var="staff" items="${dataList}" varStatus="idx">
									<tr class="${idx.index%2==0?'list1':'list2'}" id="${staff.staffId}">
								     	<td>${staff.staffId}</td>
									    <td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="Name${staff.staffId}" value="${staff.staffName}" /></td>
									    <td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="Time${staff.staffId}" value="${staff.enterTime}" /></td>
										<td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="PinyinName${staff.staffId}" value="${staff.pinyinName}" /></td>
										<td>
										  <input name="" class="newSearchButton" type="button" class="btn" onclick="update(${staff.staffId})" value="修改" /> 
										  <input name="" class="newSearchButton" type="button" class="btn" value="删除" onclick="del(${staff.staffId})"/>
									    </td>
									</tr>
									</c:forEach>
								</table> 
					      </div>
				   </div>
			</div>
			</div>
		</fieldset>
	</div>
	<jsp:include page="common/foot.jsp"></jsp:include>
</div>
<script type="text/javascript" language="javascript">
             function del(staffid){
               if(confirm("确定要删除编号为:"+staffid+"的员工吗?")){
                staffService.removeStaff(staffid,function(i){
                  if(i>0){
                   $("#"+staffid).remove();
                   alert("删除成功!");
                  }else{
                   alert("删除失败!");
                  }
                });
               }else return;
             }
             
             function selectList(){
               var id = $.trim($("#staffId").val());
               var name = $.trim($("#staffName").val());
               var enterTime = $.trim($("#enterTime").val());
               $("#loading").removeAttr("style");
               staffService.queryStaffListByClause({staffId:id,staffName:name,enterTime:enterTime},callbackFunction);
             }
             
             var callbackFunction = function(data){
              
              $("#result").empty();
              var appendData = "<table border='1' width='100%' id='resultTable'>";
               appendData+="<tr>";
               appendData+="<th>编号</th>";
               appendData+="<th>姓名</th>";
               appendData+="<th>入厂日期</th>";
               appendData+="<th>拼音索引</th>";
               appendData+="<th>操作</th>";
               appendData+="</tr>";
             for(var property in data){ 
               appendData+="<tr id='"+data[property].staffId+"'>";
               appendData+="<td>"+data[property].staffId+"</td>";
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='Name"+data[property].staffId+"' value='"+data[property].staffName+"' /></td>";
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='Time"+data[property].staffId+"' value='"+data[property].enterTime+"' /></td>";
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='PinyinName"+data[property].staffId+"' value='"+data[property].pinyinName+"' /></td>";
               appendData+="<td><input type='button' value='删除' onclick='del("+data[property].staffId+")'/>";
               appendData+="<input type='button' value='修改' onclick='update("+data[property].staffId+")'/></td>";
               appendData+="</tr>";
             }
             appendData+="</table>";
             $("#result").append(appendData);    
             };
             
             function create(){
               var name = $.trim($("#staffName").val());
               var enterTime = $.trim($("#enterTime").val());
               
               if(name==""){
                 alert("员工姓名或员工编号不能为空!");
                 return;
               }else{
                 staffService.createStaff({staffName:name,enterTime:enterTime},function(i){
                   if(i==1){
                     alert("新增成功!");
                     $("#staffId").attr("value",'');
                     $("#staffName").attr("value",'');
                     $("#enterTime").attr("value",'');
                     window.location.reload();
                   }else if(i==0){
                     alert("新增失败!已存在编号为"+id+"的员工!");
                   }else{
                     alert("新增失败!");
                   }
                 });
               }
             }
             
             function update(Id){
              var name = $.trim($("#Name"+Id).val());
              var enterTime = $.trim($("#Time"+Id).val());
              var pinyinName = $.trim($("#PinyinName"+Id).val());
              if(name==""){
                 alert("员工姓名不能修改为空!");
                 return;
               }else{
                 staffService.updateStaff({staffId:Id,staffName:name,enterTime:enterTime,pinyinName:pinyinName},function(i){
                   if(i==1){
                     alert("修改成功!");
                     window.location.reload();
                   }else{
                     alert("修改失败!");
                   }
                 });
               }
            };
           </script>
           <script type="text/javascript" src="<%=basePath%>js/jquery.js"language="javascript"></script>
           <script src='dwr/interface/staffService.js'></script>
           <script src="dwr/engine.js"></script>
</body>
</html>
